use skia_safe::{Color, EncodedImageFormat, Paint, Rect, surfaces};
use std::error::Error;
use std::fs::File;
use std::io::Write;

fn main() -> Result<(), Box<dyn Error>> {
    println!("------------------------------------------------------");

    let width = 400;
    let height = 300;

    // 创建 Surface（画布）
    let mut surface = surfaces::raster_n32_premul((width, height)).ok_or("无法创建 Surface")?;
    let canvas = surface.canvas();

    // 清空背景为白色
    canvas.clear(Color::WHITE);

    // 创建画笔
    let mut paint = Paint::default();
    paint.set_anti_alias(true);
    paint.set_color(Color::from_rgb(10, 120, 200)); // 蓝色

    // 绘制矩形
    let rect = Rect::from_xywh(50.0, 50.0, 300.0, 200.0);
    canvas.draw_rect(rect, &paint);

    // 保存为 PNG
    let image = surface.image_snapshot();

    let png_data = image.encoded_data();
    println!("测试完成！");
    println!("------------------------------------------------------");
    Ok(())
}
